package com.mycjj.android.http;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.mycjj.android.MyCjjApplication;
import com.mycjj.android.R;


public class ProjectAsyncHttpClient extends AsyncHttpClient{
	
	private static final String TAG = "ProjectAsyncHttpClient";
	private static final int TIME_OUT = 10000;
	
	public ProjectAsyncHttpClient(){
		super();
		setTimeout(TIME_OUT);
	}
	
	public void get(Context context, String url, RequestParams params, ProjectAsyncHttpResponseHandler responseHandler) {
		if(!MyCjjApplication.getInstance().isConnect()){
			Log.d(TAG, "网络连接失败");
			this.showDialog(context.getResources().getString(R.string.CannotReadNetworkData),context);
		}
		
		super.get(context, url, params, responseHandler);
	}
	
	private void showDialog(String msg,Context context){
		AlertDialog alertDialog = MyCjjApplication.getInstance().getAlertDialog();
		if( alertDialog != null && alertDialog.isShowing() ){
			return;
		}else{
			AlertDialog.Builder build = new AlertDialog.Builder(context);
			build.setTitle("温馨提示");
			build.setMessage(msg);
			build.setPositiveButton("确定", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface arg0, int arg1) {
//					ad.dismiss();
				}
			});
			AlertDialog ad = build.create();
			MyCjjApplication.getInstance().setAlertDialog(ad);
			ad.show();
		}
		
	}
}
